#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

void swap(int* a, int* p)
{
	int tem = *a;
	*a = *p;
	*p = tem;
}
void Quicksort(int* a, int left, int right)
{
	if (left >= right)
	{
		return;
	}
	int keyi = partion(a, left, right);
	Quicksort(a, left, keyi - 1);
	Quicksort(a, keyi + 1,right);
}

int partion(int* a, int left, int right)
{
	int keyi = left;
	while (left < right)
	{
		while (left < right && a[right] >= a[keyi])
		{
			right--;
		}
		while (left < right && a[left] <= a[keyi])
		{
			left++;
		}
		swap(&a[left], &a[right]);
	}
	swap(&a[left], &a[keyi]);
		return left;
}

int main()
{
	int arr[10] = { 2,3,1,6,7,9,4,5,8,1 };
	Quicksort(arr, 0, sizeof(arr) / sizeof(int)-1);
	for (int i = 0; i < 10; i++)
	{
		printf("%d ", arr[i]);
	}
}